*===============================================================================
* Do-file creates "Table A5: Administrative Dataset: Violence and M-Paisa Use, Fixed Effects Sensitivity"
*===============================================================================
clear 
set more off

cd "~/Dropbox/VFD/REStat_Native_Files/Stata_Files"
local output "~/Dropbox/VFD/REStat_Native_Files/Stata_Files/Output"



use "monthpanel_analysis.dta", clear
keep if salary==1
gen trimmedobs=0
sum balance, d
replace trimmedobs =1 if (balance <=r(p99) & balance>=r(p1))
replace trimmedobs =. if balance ==.
bys identityid: egen trimmed_extusers = min(trimmedobs)
keep if trimmed_extusers==1


* Get estimation sample
qui:reghdfe balance d_violence_10km, absorb(ym c.ym#district identityid) cl(district)
gen sample=e(sample)


* Table A5, Panel A: Main violence
estimates clear
foreach X in d_violence {
	foreach y in balance numtxns { 
		reg `y' `X'_10km if sample, cl(district) 
		est store `y'_fe0
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary"
		estadd local monthFE "NO"
		estadd local distFE "NO"
		estadd local individFE "NO"

		reghdfe `y' `X'_10km if sample, absorb(ym) cl(district) 
		est store `y'_fe1
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary"
		estadd local monthFE "YES"
		estadd local distFE "NO"
		estadd local individFE "NO"

		reghdfe `y' `X'_10km if sample, absorb(ym c.ym#district) cl(district)
		est store `y'_fe2
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary"
		estadd local monthFE "YES"
		estadd local distFE "YES"
		estadd local individFE "NO"

		reghdfe `y' `X'_10km, absorb(ym c.ym#district identityid) cl(district)
		est store `y'_fe3
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary"
		estadd local monthFE "YES"
		estadd local distFE "YES"
		estadd local individFE "YES"
	}
	estout balance_* numtxns_*  ///
	using "`output'/table_a5a.tex", cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) ///
	starlevels(* .1 ** .05 *** .01) style(tex) keep(`X'_10km) mlabels(, dep) collabels(,none) ///
	stats(samplestr in_sample_mean nID N_clust N r2 monthFE individFE distFE, fmt(0 3 0 0 0 3 0 0 0) ///
	label("Sample" "Mean Dep Var" "\# Individuals" "\# Clusters" "\# Observations" "R-Squared" "Month-Year FE" "Individual FE" "District Trends")) ///
	label title("Administrative Dataset: Violence and M-Paisa Use") replace
}

* Table A5, Panel B: By Violence Categories
estimates clear
	foreach y in balance numtxns { 
		reg `y' d_df_10km d_idf_10km d_ied_10km if sample, cl(district) 
		est store `y'_fe0
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary"
		estadd local monthFE "NO"
		estadd local distFE "NO"
		estadd local individFE "NO"

		reghdfe `y' d_df_10km d_idf_10km d_ied_10km  if sample, absorb(ym) cl(district) 
		est store `y'_fe1
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary"
		estadd local monthFE "YES"
		estadd local distFE "NO"
		estadd local individFE "NO"

		reghdfe `y' d_df_10km d_idf_10km d_ied_10km  if sample, absorb(ym c.ym#district) cl(district)
		est store `y'_fe2
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary"
		estadd local monthFE "YES"
		estadd local distFE "YES"
		estadd local individFE "NO"

		reghdfe `y' d_df_10km d_idf_10km d_ied_10km, absorb(ym c.ym#district identityid) cl(district)
		est store `y'_fe3
		estadd ysumm, mean prefix(in_sample_)
		unique identityid if e(sample)
		estadd local nID = r(unique)
		estadd local samplestr "Salary"
		estadd local monthFE "YES"
		estadd local distFE "YES"
		estadd local individFE "YES"
	}
estout balance_* numtxns_*  ///
using "`output'/table_a5b.tex", cells(b(fmt(%9.3f) star) se(par fmt(%9.3f))) ///
starlevels(* .1 ** .05 *** .01) style(tex) keep(d_df_10km d_idf_10km d_ied_10km) ///
mlabels(, dep) collabels(,none) ///
stats(samplestr in_sample_mean nID N_clust N r2 monthFE individFE distFE, fmt(0 3 0 0 0 3 0 0 0) ///
label("Sample" "Mean Dep Var" "\# Individuals" "\# Clusters" "\# Observations" "R-Squared" "Month-Year FE" "Individual FE" "District Trends")) ///
label title("Administrative Dataset: Violence and M-Paisa Use") replace






